package linhnv.app;

import android.app.Activity;
import android.app.ActivityGroup;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class Home extends ActivityGroup {
	
	private LocalActivityManager activityManager;
	private static GridView gridview;
	private boolean isHomeCurrentView = true;
		@Override
		public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        
	        //Remove title bar
			this.requestWindowFeature(Window.FEATURE_NO_TITLE);
			//Remove notification bar
			this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
			
	        setContentView(R.layout.home);
	        activityManager = getLocalActivityManager();
	        
	        gridview = (GridView) findViewById(R.id.gridview);
	        gridview.setAdapter(new ImageAdapter(this, activityManager));
	        
	        AudioStreaming.setHomeSelf(this);
	    }
		
		@Override
		protected void onDestroy() {
			// TODO Auto-generated method stub
			Log.w("Linhnv","========================ondestroy");
			super.onDestroy();
		}

		@Override
		public boolean onKeyDown(int keyCode, KeyEvent event) {
			if(keyCode == KeyEvent.KEYCODE_BACK)
			{
				if(!isHomeCurrentView)
				{
					reset();
					// Back to grid view
					return true;
				}
			}
			// TODO Auto-generated method stub
			return super.onKeyDown(keyCode, event);
		}
		
		
		public void reset()
		{
			setContentView(gridview);
			isHomeCurrentView = true;
			AudioStreaming.frameTitleLayout.getLayoutParams().height = (int) (getResources().getDisplayMetrics().density * 40);
		}
		
		public void setHomeCurrentView(boolean isHomeCurrentView)
		{
			this.isHomeCurrentView = isHomeCurrentView;
		}
}
